query <- function(sparql, uri){
	q <- .jnew("rsparql/SparqlQuery") # create instance
	print("Executing query...")
	.jcall(q, "V", "execute", sparql, uri)
	rows <- .jcall(q, "I", "rows")
	cols <- .jcall(q, "I", "cols")
	print(paste("Received",rows,"rows and",cols,"columns. Converting to matrix..."))
	data <- matrix(nrow=rows,ncol=cols)
	for (r in seq(0,rows-1)) {
		for (c in seq(0,cols-1)) {
			row <- r+1
			col <- c+1
			data[row,col] <- .jsimplify(.jcall(q, "Ljava/lang/Object;", "cell", r, c))
		}
	}
	colnames(data) <- .jcall(q, "[S", "colNames")
	.jcall(q, "V", "clear")
	print("Query completed.");
	return( melt(as.data.frame(data)) )
}
